package com.cskaoyan.controller.vx.comment;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.vxBo.comment.CommentPostBo;
import com.cskaoyan.bean.vo.vxVo.comment.CommentCountVo;
import com.cskaoyan.bean.vo.vxVo.comment.CommentListVo;
import com.cskaoyan.bean.vo.vxVo.comment.CommentPostVo;
import com.cskaoyan.bean.vo.vxVo.comment.TVO;
import com.cskaoyan.service.vx.comment.CommentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: 陈慧颖
 * @time: Created by chy on 2022/6/7 20:46
 */
@RestController(value = "wxcommentcontroller")
@RequestMapping("wx/comment")
public class CommentController {

    @Autowired
            @Qualifier("vxcommentserviceimpl")
    CommentService commentService;

    @RequestMapping("list")
    public BaseRespVo list(Integer valueId, Integer type, Integer limit, Integer page, Integer showType) {

        List<CommentListVo> commentListVos = commentService.list(valueId, type, limit, page, showType);
        PageInfo<CommentListVo> commentListVoPageInfo = new PageInfo<>(commentListVos);
        return BaseRespVo.ok(TVO.data(commentListVoPageInfo.getTotal(), commentListVoPageInfo.getPages(), limit, page
                , commentListVos));
    }

    /**
     * 实现 GET /wx/comment/count?valueId=1057036&type=0
     * 接收参数 为 valueId 和 type ;
     * @param valueId
     * @param type
     * @return
     */
    @RequestMapping("count")
    public BaseRespVo count(Integer valueId, Integer type ){
       CommentCountVo commentCountVo      =  commentService.count(valueId,type);

              return BaseRespVo.ok(commentCountVo);
    }
    /**
     * POST /wx/comment/post
     * 携带参数
     * {"type":1,"valueId":"368","content":"弟弟","star":5,"hasPicture":true,"picUrls":["http://182.92.235.201:8083/wx/storage/fetch/mc7kwj6ails3yk02an4z.png"]}
     */
    @RequestMapping("post")
    public  BaseRespVo post(@RequestBody CommentPostBo commentPostBo){
    CommentPostVo commentPostVo =        commentService.post(commentPostBo);
        return BaseRespVo.ok(commentPostVo);
    }
}
